package com.tianyi.sfzy1.controller;

import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Psychologicalassessment;
import com.tianyi.sfzy1.service.PsychologicalassessmentService;
import com.tianyi.sfzy1.util.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/psychologicalassessment")
public class PsychologicalassessmentController {
@Autowired
    PsychologicalassessmentService psychologicalassessmentService;
        @PostMapping
      public R addPsychologicalassessment(Psychologicalassessment psychologicalassessment) {

          int i=psychologicalassessmentService.addPsychologicalassessment(psychologicalassessment);
          if(i>0){
              return R.ok(null);
          }
          else {
              return  R.fail("添加失败");
          }
      }
      @DeleteMapping
        public R deleteManyPsychologicalassessment(@RequestBody List<Integer> Ids) {
            int i=psychologicalassessmentService.deleteManyPsychologicalassessment(Ids);
          if(i>0){
              return R.ok(null);
          }
          else {
              return  R.fail("删除失败");
          }


      }
      @DeleteMapping("/id")
      public R deleteOnePsychologicalassessment( long id) {
            int i=psychologicalassessmentService.deleteManyPsychologicalassessmentByPsychologicalassessmentId(id);
          if(i>0){
              return R.ok(null);
          }
          else {
              return  R.fail("删除失败");
          }

      }
      @PutMapping
    public R updateService(Psychologicalassessment psychologicalassessment) {
          System.out.println(psychologicalassessment);
            int i=psychologicalassessmentService.updateSelective(psychologicalassessment);
          if(i>0){
              return R.ok(null);
          }
          else {
              return  R.fail("修改失败");
          }

      }
      @GetMapping
    public R searcAll() {
            List<Psychologicalassessment> lists=psychologicalassessmentService.selectAllPsychologicalassessment();
            return R.ok(lists);
      }
//模糊搜索
      @GetMapping("/search")
    public R searcBySearch( Psychologicalassessment example) {
          List<Psychologicalassessment> lists = psychologicalassessmentService.selectPsychologicalassessmentBy(example);
          return R.ok(lists);


      }
//      分页查询
    @GetMapping("/fenye")
    public R searchfenye(int pageNum,int pageSize ){
        PageInfo<Psychologicalassessment> list =psychologicalassessmentService.fenyechaxun(pageNum,pageSize);
        return R.ok(list);

    }



}
